cmake_minimum_required(VERSION 3.19)
project(pyExt)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(LINK_DIR /Users/haoran/Downloads/wfdb/lib)
LINK_DIRECTORIES(${LINK_DIR})
LINK_DIRECTORIES("H:/tmp/wxWidgets-3.1.3/x86_build/lib/vc_dll")
LINK_DIRECTORIES("H:/tmp/sqlite3/" )

#message(${VAR1})
#RELEASE x64
# /D "Py_BUILD_CORE" /D "_CONSOLE" /D "WIN32" /D "PY3_DLLNAME=L\"python3\"" /D "_WIN64" /D "_M_X64" /D "NDEBUG" /D "_MBCS"
#DEBUG
# /D "Py_BUILD_CORE" /D "_CONSOLE" /D "WIN32" /D "PY3_DLLNAME=L\"python3_d\"" /D "_WIN64" /D "_M_X64" /D "_DEBUG" /D "_MBCS"
#WIN32
#/D "Py_BUILD_CORE" /D "_CONSOLE" /D "WIN32" /D "PY3_DLLNAME=L\"python3_d\"" /D "_WIN32" /D "_DEBUG" /D "_MBCS"
add_definitions("-D WXUSINGDLL")
#add_definitions("-D WIN32")
add_definitions("/D _WIN64")
#C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\vcruntime.h(253): error C4235: 使用了非标准扩展: 不支持在此结构上使用“__unaligned”关键字
#if defined _M_X64 || defined _M_ARM || defined _M_ARM64
#define _UNALIGNED __unaligned
#else
#define _UNALIGNED
#endif
#add_definitions("/D _M_X64")
set(BUILD_USE_64BITS on)

#__WXMAC__
#add_definitions("-D __WXGTK__")
add_definitions("-D __WXMSW__")
#add_definitions("-D _DEBUG_" )
#__WXMSW__
#add_definitions("-D _UNICODE")
add_definitions( "-D _MBCS" )
add_definitions("-D _WINDOWS")
add_definitions( "-D PY_SSIZE_T_CLEAN")

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set( preference_include ${CMAKE_CURRENT_SOURCE_DIR}/../libpreference/ )
#E:/tmp/rapid-svn_cmake/windows/clientV1/../libpreference/
#E:\tmp\rapid-svn_cmake\windows\cmake-build-debug\libpreference
#${CMAKE_CURRENT_SOURCE_DIR}
#E:/tmp/rapid-svn_cmake/windows/clientV1/
#${CMAKE_CURRENT_SOURCE_DIR}/..
#E:/tmp/rapid-svn_cmake/windows/
#${CMAKE_CURRENT_SOURCE_DIR}/../cmake-build-debug/libpreference
#E:\tmp\rapid-svn_cmake\windows\cmake-build-debug\libpreference
message( ${preference_include} )

LINK_DIRECTORIES( ${preference_include}
        "h:/tmp/mysql-connector-c-6.1.11-win32/lib/vs14/debug"
        "H:/tmp/libssh2/cmake-build-debug/src"
        #"G:/Python39/libs"
        "H:/tmp/Python-3.9.2/PCbuild/amd64"
        ${CMAKE_CURRENT_SOURCE_DIR}/../cmake-build-debug/libpreference
        ${CMAKE_CURRENT_SOURCE_DIR}/../cmake-build-debug/repLib )

#add_executable(windows main.cpp)
#file(GLOB MD5_FILES ../repLib/src/md5.cpp)
#file(GLOB SCP_FILES ../repLib/src/scp.cpp)
#file(GLOB SQL_FILES ../repLib/src/sql.cpp)

#aux_source_directory(src SOURCE_FILES )

#/machine:X86
message(${CMAKE_EXE_LINKER_FLAGS})

#/subsystem:console
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#/machine:X86 /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup

#if(MSVC)
#    set(CMAKE_CREATE_WIN32_EXE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
#endif(MSVC)

#如果您只是直接执行add_executable()命令，则会将/SUBSYSTEM:CONSOLE /ENTRY:"mainCRTStartup"传递给链接器。
add_library(pyExt MODULE ${SOURCE_FILES} src/postFile.cpp)

target_link_libraries( pyExt
        preference.lib
        repLib.lib
        mysqlclient.lib
        sqlite3.lib
        libssh2.lib
        python3.lib
        python39.lib
        python39_d.lib
        wxbase31ud.lib
        wxbase31ud_net.lib
        wxbase31ud_xml.lib
        wxexpatd.lib
        wxjpegd.lib
        wxmsw31ud_adv.lib
        wxmsw31ud_aui.lib
        wxmsw31ud_core.lib )

#H:\tmp\wxWidgets-3.1.3\x86_build\lib\vc_dll
#target_link_libraries(windows  )

target_include_directories(pyExt PUBLIC
        "H:/tmp/wxWidgets-3.1.3/include"
        #"H:/tmp/wxWidgets-3.1.3/include/wx"
        #"H:/tmp/wxWidgets-3.1.3/include/msvc"
        "H:/tmp/wxWidgets-3.1.3/x86_build/lib/vc_dll/mswud"
        #"G:/Python39/include"
        "H:/tmp/Python-3.9.2/Include"
        "H:/tmp/Python-3.9.2/PC"
        "H:/tmp/sqlite3"
        ${preference_include}
        "H:/tmp/mysql-connector-c-6.1.11-win32/include"
        "H:/tmp/libssh2/include"
        "${CMAKE_CURRENT_SOURCE_DIR}/../repLib/src"
        )

#把生成时间写进头文件字符串里作为软件的字符资源
#LINK_LIBRARIES()
#H:\tmp\wxWidgets-3.1.3\x86_build\lib\vc_dll
if(WIN32)
    set_target_properties( pyExt PROPERTIES SUFFIX ".pyd")
endif()